/*
 * web 2.0 MBDS 2012 Michel Buffa
 */
package com.orange.smartcity.android.tools;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.orange.smartcity.android.R;
import com.orange.smartcity.android.SmartCityApplication;
import com.orange.smartcity.android.activity.Home;
import com.orange.smartcity.android.activity.Settings;

/*
 * Class to create menu
 * FO && AL
 */
public class ApplicationMenuUtils {
	public static void onCreateOptionsMenu(Activity context, Menu menu) {
		MenuInflater inflater = context.getMenuInflater();
		inflater.inflate(R.menu.menu, menu);
	}

	public static void onPrepareOptionsMenu(Activity context, Menu menu) {
		menu.findItem(R.id.menu_delete).setVisible(true);
		menu.findItem(R.id.menu_settings).setVisible(true);

		// the menu Hit it visible just for the user object in the case screen
		// of object detail
		if (context.getTitle().toString().equalsIgnoreCase("Home")) {
			// menu.findItem(R.id.startNFC).setVisible(true);
		}
		Log.i("le contexte de la methode onPrepareOptionsMenu ", context
				.getTitle().toString());
	}

	public static void onOptionsItemSelected(Activity context, MenuItem item) {
		switch (item.getItemId()) {
		case R.id.menu_delete:
			Intent i = new Intent(context, Home.class);
			context.startActivity(i);
			break;

		case R.id.menu_settings:
			Intent preferences = new Intent(context, Settings.class);
			context.startActivity(preferences);
			break;
		case R.id.menu_mylocation:
			Intent intent =GpsLocationUtils.launchMaps();
			context.startActivity(intent);
			break;
		case R.id.menu_exit:
			// Clear passwords and other settings
			context.getSharedPreferences(SmartCityApplication.PREFS,
					Context.MODE_PRIVATE).edit().clear().commit();

			// init!!!
			Intent login = new Intent(context, Home.class);
			context.startActivity(login);

			context.finish();
			break;
		}
	}
	
}
